package concurrent.producerconsumer;

import java.util.concurrent.LinkedBlockingQueue;

/**
 * Author: Jason Wu
 * Date  : 2013-12-19
 */
public class ProducerConsumerMain {
    public static void main(String args[]) throws InterruptedException {
        LinkedBlockingQueue taskQueue = new LinkedBlockingQueue();
        final DynamicThreadPool dynamicThreadPool = new DynamicThreadPool(taskQueue, 3);
        final LinkedBlockingQueue<Task> queue = new LinkedBlockingQueue<Task>(50);
        Thread prodThread = new Thread(new Producer(queue, 10), "Producer");
        Thread consThread = new Thread(new Consumer(queue, dynamicThreadPool), "Consumer");
        prodThread.start();
        consThread.start();

        Thread.sleep(10000);
        new Thread(new Producer(queue, 2), "Producer").start();
        Thread.sleep(5000);
        new Thread(new Producer(queue, 20), "Producer").start();
    }
}
